import {http} from '@/plugins/net.js'
export const list = async (searchData,currPage,pageSize) => {
    let url = '/scheduled/list?1=1'
            if (searchData && searchData.scheduledName) {
                url = url + `&scheduledName=` + searchData.scheduledName
            }
    if (currPage) {
        url += `&currentPage=${currPage}`
    }
    if (pageSize) {
        url += `&pageSize=${pageSize}`
    }
    const res = await http(url,'get',null)
    if (res) {
        return res
    }
}

/**
 * 获取所有可添加任务
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getAllTask = async () => {
    let url = `/scheduled/allTask`
    const res = await http(url,'get')
    if (res) {
        return res
    }
}

/**
 * 添加任务
 * @param task
 * @returns {Promise<void>}
 */
export const addTask = async (task) => {
    let url = `/scheduled/add`
    await http(url,'post',task)
}

/**
 * 检查任务是否已经添加过
 * @param taskId
 * @returns {Promise<void>}
 */
export const checkTaskIsExist = async (taskId) => {
    let url = `/scheduled/checkTaskIsExist?taskId=${taskId}`
    const res = await http(url,'post',null)
    if (res) {
        // 1 已经存在 0 不存在
        return res
    }
}

/**
 * 启动或停止定时任务
 * @param taskId
 * @param status
 * @returns {Promise<void>}
 */
export const stopOrStartTask = async (taskId,status) => {
    let url = `/scheduled/stopOrStartTask?scheduledId=${taskId}&status=${status}`
    await http(url,'post',null)
}


/**
 * 删除任务
 * @param taskId
 * @returns {Promise<void>}
 */
export const deleteTask = async (taskId) => {
    let url = `/scheduled/delete?taskId=${taskId}`
    await http(url,'delete')
}

/**
 * 更新任务
 * @param task
 * @returns {Promise<void>}
 */
export const updateTask = async (task) => {
    let url = `/scheduled/update`
    await http(url,'update',task)
}